package cn.ld.fj.service.desk;

import cn.ld.fj.dao.desk.DeskShopDao;
import cn.ld.fj.dao.desk.DeskShopOrderInfoDAO;
import cn.ld.fj.entity.DeskShop;
import cn.ld.fj.entity.DeskShopOrderInfo;
import net.esoar.modules.orm.Page;
import net.esoar.modules.orm.PropertyFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 安全相关实体的管理类, 包括用户,角色,资源与授权类.
 *
 * @author fly
 */
//Spring Bean的标识.
@Component
//默认将类中的所有函数纳入事务管理.
@Transactional
public class DeskShopOrderInfoManager {

    private static Logger logger = LoggerFactory.getLogger(DeskShopOrderInfoManager.class);
    @Autowired
    private DeskShopOrderInfoDAO deskShopOrderInfoDAO;


    //-- User Manager --//
    @Transactional(readOnly = true)
    public DeskShopOrderInfo getOne(Long id) {
//        return deskShopDao.get(id);
        List<DeskShopOrderInfo> deskShopList = deskShopOrderInfoDAO.findBy("id", id);
        if (deskShopList != null && deskShopList.size() > 0)
            return deskShopOrderInfoDAO.findBy("id", id).get(0);
        return null;
    }

    public void save(DeskShopOrderInfo entity) {
        deskShopOrderInfoDAO.save(entity);
    }

    @Transactional(readOnly = true)
    public Page<DeskShopOrderInfo> getPage(Page<DeskShopOrderInfo> page, List<PropertyFilter> filters) {
        return deskShopOrderInfoDAO.findPage(page, filters);
    }

    public void delete(Long id) {
        deskShopOrderInfoDAO.delete(id);
    }


    @Transactional(readOnly = true)
    public List<DeskShopOrderInfo> findAll() {
        return deskShopOrderInfoDAO.getAll();
    }

    public List<Long> findDeskIdByDate(){
        String hql="select deskShopId from cn.ld.fj.entity.DeskShopOrderInfo edoi\n" +
                "where edoi.orderTime > NOW()";
        return deskShopOrderInfoDAO.find(hql);
    }

    public List<DeskShopOrderInfo> getDeskShopOrderInfoByDeskId(long deskShopId){
        String hql="from cn.ld.fj.entity.DeskShopOrderInfo edoi\n" +
                "where edoi.deskShopId ="+deskShopId+" and edoi.orderTime > NOW()";
        return deskShopOrderInfoDAO.find(hql);
    }

}
